home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / bakeSoft.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.0 KB  |  175 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.  
  18. /*
  19.  _______________________________________________________________________
  20.  ______________       A L I A S  /  W A V E F R O N T       ____________
  21.  |
  22.  |     $Source: /vobs/aw/Maya/src/DynUISlice/Unsupported/bakeSoft.mel $
  23.  |
  24.  |   $Author: southard $
  25.  |   $Revision: /main/1 $
  26.  |   $Date: 1997/11/24 15:20:19 $
  27.  |
  28.  |   Original Author:
  29.  |       Jason Schleifer
  30.  |
  31.  |   Description:
  32.  |         Bakes out softbody animations so there are curves for all the 
  33.  |         cv's.
  34.  |
  35.  |     Usage:
  36.  |         Select the softBody you want and type:
  37.  |
  38.  |                bakeSoft <start frame> <end frame> <step>
  39.  |
  40.  |         ex:
  41.  |
  42.  |                bakeSoft 1 200 1;
  43.  |
  44.  ______________       A L I A S  /  W A V E F R O N T       ____________
  45.  _______________________________________________________________________
  46.  */
  47.  
  48. //  Version information
  49. //  -------------------
  50. //
  51. //    1.0        11/6/97        Info:        First release.  
  52. //                        Known bugs: Doesn't work on Polys.
  53. //
  54.  
  55.  
  56. global proc bakeSoft ( int $start, int $end, int $by)
  57. {
  58.     // variable declaration
  59.     string $softShape;
  60.     string $object;
  61.     string $item;
  62.     string $newObject;
  63.     string $particleShape;
  64.     string $parent;
  65.     string $objectParent;
  66.     string $objSel;
  67.     int $numCp;
  68.     string $softType;
  69.  
  70.     // get the name of the object selected
  71.     
  72.     $tmp = `ls -sl`;
  73.     $objSel = $tmp[0];
  74.  
  75.     // figure out what type of object this is
  76.  
  77.     $shapes = `listRelatives -s $objSel`;
  78.     
  79.     for ($item in $shapes)
  80.     {
  81.         $type = `ls -showType $item`;
  82.         if ($type[1] == "nurbsSurface")
  83.         {
  84.             $numCp = ((`getAttr ($item + ".spansU")` + 3) * (`getAttr ($item + ".spansV")` + 3) - 1);
  85.             $softShape = $item;
  86.             $softType = "nurbsSurface";
  87.         }
  88.         if ($type[1] == "nurbsCurve")
  89.         {
  90.             $numCp = ((`getAttr ($item + ".spans")` + 3) -1);
  91.             $softShape = $item;
  92.             $softType = "nurbsCurve";
  93.         }
  94.         if ($type[1] == "lattice")
  95.         {
  96.             $numCp = ((`getAttr ($item + ".sDivisions")`) * (`getAttr ($item + ".tDivisions")`) * (`getAttr ($item + ".uDivisions")`) -1);
  97.             $softShape = $item;
  98.             $softType = "lattice";
  99.         }
  100.         if ($type[1] == "mesh")
  101.         {
  102.             int $tmpCp[]= `polyEvaluate -v $item`;
  103.             $numCp = ($tmpCp[0] -1);
  104.             $softShape = $item;
  105.             $softType = "mesh";
  106.             print ("bakeSoft doesn't really work at all on polys.. you're on your own... \n");
  107.         }
  108.         if ($type[1] == "particle")
  109.             $particleShape = $item;
  110.     }
  111.     print ("This is a " + $softType + ".  It has " + $numCp + " points.\n");
  112.  
  113.     // get the name of the parent of the softObject
  114.     $tmp = `listRelatives -p $softShape`;
  115.     $parent = $objSel;
  116.  
  117.     // duplicate shape to get new object
  118.     $tmp = `duplicate $softShape`;
  119.     $object = $tmp[0];
  120.     
  121.     // cycle through the frame range
  122.     for ($x = $start; $x <=$end; $x = $x + $by)
  123.     {    
  124.         currentTime $x;
  125.         
  126.         // for each of the cv's bake out the animation
  127.         for ($i = 0; $i <= $numCp; $i++)
  128.         {
  129.             $item = ($softShape + ".cp[" + $i+"]");
  130.             $value = `xform -q -ws -t $item`;
  131.             $newObject = `substitute $softShape $item $object`;
  132.             move $value[0] $value[1] $value[2] $newObject;
  133.             setKeyframe -at xValue $newObject; 
  134.             setKeyframe -at yValue $newObject; 
  135.             setKeyframe -at zValue $newObject; 
  136.         }
  137.  
  138.     }
  139.  
  140.     // delete the particle
  141.     delete $particleShape;
  142.  
  143.     // break the anim curves on the new object & put them on the original
  144.     // softBody
  145.     currentTime $start;
  146.     for ($i = 0; $i <= $numCp ; $i++)
  147.     {
  148.             $xValueCon = `listConnections -p true ($object + ".cp["+$i+"].xValue")`;
  149.             $yValueCon = `listConnections -p true ($object + ".cp["+$i+"].yValue")`;
  150.             $zValueCon = `listConnections -p true ($object + ".cp["+$i+"].zValue")`;
  151.         
  152.             if (size ($xValueCon) >0)
  153.             {
  154.                 $cmd = ("connectAttr " + $xValueCon[0] + " " + $softShape + ".cp["+$i+"].xValue");
  155.                 eval $cmd;
  156.                 $cmd = ("connectAttr " + $yValueCon[0] + " " + $softShape + ".cp["+$i+"].yValue");
  157.                 eval $cmd;
  158.                 $cmd = ("connectAttr " + $zValueCon[0] + " " + $softShape + ".cp["+$i+"].zValue");
  159.                 eval $cmd;
  160.                 
  161.                 disconnectAttr $xValueCon[0] ($object + ".cp["+$i+"].xValue");
  162.                 disconnectAttr $yValueCon[0] ($object + ".cp["+$i+"].yValue");
  163.                 disconnectAttr $zValueCon[0] ($object + ".cp["+$i+"].zValue");
  164.             }
  165.     }
  166.  
  167.  
  168.     // delete the duplicateShape
  169.     select -r $object;
  170.     pickWalk -d "up";
  171.     delete;
  172.  
  173.     print "Done..\n";
  174. }
  175.